<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 宏任务
      setTimeout(function () {
        console.log(1)
      })
      new Promise(function (resolve, reject) {
        console.log(2)
        resolve(3)
      }).then(function (val) {
        // 微任务
        console.log(val) // 3
      })
      console.log(4)
      // 打印的结果
      // 2 4 3 1
    </script>
  </body>
</html>
